package com.li.spark0615.zhibiao

import org.apache.spark.sql.{DataFrame, SparkSession}

object Two {
  def main(args: Array[String]): Unit = {

    System.setProperty("HADOOP_USER_NAME","root")

    val session = SparkSession
      .builder()
      .appName("li")
      .master("local[*]")
      .enableHiveSupport()
      .config("hive.metastore.uris", "thrift://192.168.23.40:9083")
      .config("dfs.client.use.datanode.hostname", "true")
      .config("hive.exec.dynamic.partition.mode", "nonstrict")
      .getOrCreate()


    session.sql(
      """
        |select name , sum(comnum) from ods.lx_area where name='江苏省' group by name
        |""".stripMargin).show()
  }

  def readMysql(session:SparkSession,table:String):DataFrame={
    val reader: DataFrame = session
      .read
      .format("jdbc")
      .option("url", "jdbc:mysql://192.168.23.34:3306/laxaio?useSSL=false")
      .option("user", "root")
      .option("password", "123456")
      .option("dbtable", "( select * from  " + table + " limit 600 ) temp")
      .load()

    reader
  }
}
